package com.zzyweb.rentalcarsys.utils;

import lombok.Data;

/**
 * @author zhiyi
 * @date 9/22/25
 **/
@Data
public class ResponseObject<T>{
    private Integer code;
    private String msg;
    private boolean success;
    private T data;

    private ResponseObject() {
    }

    private ResponseObject(Integer code, String msg, boolean success, T data) {
        this.code = code;
        this.msg = msg;
        this.success = success;
        this.data = data;
    }

    public static <T> ResponseObject ok() {
        return new ResponseObject(200,"请求成功", true,null);
    }

    public static <T> ResponseObject<T> ok(T data){
        return new ResponseObject<T>(200,"请求成功", true,data);
    }

    public static ResponseObject error() {
        return new ResponseObject(500,"请求失败", false,null);
    }

    public ResponseObject<T> code(Integer code) {
        this.setCode(code);
        return this;
    }

    public ResponseObject<T> msg(String msg) {
        this.setMsg(msg);
        return this;
    }

    public ResponseObject<T> success(boolean success) {
        this.setSuccess(success);
        return this;
    }

    public ResponseObject<T> data(T data) {
        this.setData(data);
        return this;
    }
}
